package com.eastfair.visitor.controller;

import com.eastfair.visitor.dto.*;
import com.eastfair.visitor.entity.ReservationAuditRecord;
import com.eastfair.visitor.service.ReservationAuditRecordService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.visitor.service.ReservationService;
import com.eastfair.visitor.vo.ReservationAuditRecordVO;
import com.eastfair.visitor.vo.ReservationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 访客预约审核记录
 * </p>
 *
 * @author lyw
 * @date 2022-11-18
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/reservationAuditRecord")
@Api(value = "ReservationAuditRecord", tags = "访客预约审核记录")
@PreAuth(replace = "visitor:reservationAuditRecord:")
public class ReservationAuditRecordController extends SuperController<ReservationAuditRecordService, Long, ReservationAuditRecord, ReservationAuditRecordPageQuery, ReservationAuditRecordSaveDTO, ReservationAuditRecordUpdateDTO> {

    @Autowired
    private EchoService echoService;
    @Autowired
    private ReservationAuditRecordService reservationAuditRecordService;

    @Override
    public void handlerResult(IPage<ReservationAuditRecord> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ReservationAuditRecord> reservationAuditRecordList = list.stream().map((map) -> {
            ReservationAuditRecord reservationAuditRecord = ReservationAuditRecord.builder().build();
            //TODO 请在这里完成转换
            return reservationAuditRecord;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(reservationAuditRecordList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ReservationAuditRecordPageQuery> params) {
        ReservationAuditRecordPageQuery pageQuery = params.getModel();

    }

    /**
     * 查询访客列表分页
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "查询访客列表分页")
    @PostMapping(value = "/queryReservationList")
    public R<IPage<ReservationAuditRecordVO>> queryReservationList(@RequestBody PageParams<ReservationAuditRecordPageQuery> params) {
        IPage<ReservationAuditRecordVO> page = reservationAuditRecordService.queryReservationList(params);
        return R.success(page);

    }

    /**
     * 查询移动端访客列表分页
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "查询移动端访客列表分页")
    @PostMapping(value = "/page/queryReservationList")
    public R<IPage<ReservationAuditRecordVO>> pageQueryReservationList(@RequestBody PageParams<ReservationAuditRecordPageQuery> params) {
        IPage<ReservationAuditRecordVO> page = reservationAuditRecordService.queryReservationList(params);
        return R.success(page);

    }

    /**
     * 取消访客预约
     *
     * @return
     */
    @ApiOperation(value = "取消访客预约")
    @PostMapping(value = "/delReservationInfo")
    public R<Boolean> delReservationInfo(@RequestBody ReservationAuditRecordUpdateDTO reservationAuditRecordUpdateDTO) {
        return R.success(reservationAuditRecordService.delReservationInfo(reservationAuditRecordUpdateDTO));
    }


    /**
     * 修改访客审核状态
     * @param reservationAuditRecordUpdateDTO
     * @return
     */
    @ApiOperation(value = "修改访客审核状态")
    @PostMapping(value = "/updateAuditStatusById")
    public R<Boolean> updateAuditStatusById (@RequestBody ReservationAuditRecordUpdateDTO reservationAuditRecordUpdateDTO) {

        return R.success(reservationAuditRecordService.updateAuditStatusById(reservationAuditRecordUpdateDTO));
    }


    /**
     * 添加访客预约信息
     * @param reservationAuditRecordSaveDTO
     * @return
     */
    @ApiOperation(value = "添加访客预约信息")
    @PostMapping(value = "/saveReservationInfo")
    public R<Boolean> saveReservationInfo (@RequestBody ReservationAuditRecordSaveDTO reservationAuditRecordSaveDTO) {

        return R.success(reservationAuditRecordService.saveReservationInfo(reservationAuditRecordSaveDTO));
    }


    /**
     * 通过id查询访客信息
     *
     * @return
     */
    @ApiOperation(value = "通过id查询访客信息")
    @PostMapping(value = "/getReservationInfoById")
    public R<ReservationAuditRecordVO > getReservationInfoById(@RequestBody ReservationAuditRecordDTO reservationAuditRecordDTO) {
        return R.success(reservationAuditRecordService.getReservationInfoById(reservationAuditRecordDTO));
    }


    /**
     * 删除访客预约记录
     * @param reservationAuditRecordUpdateDTO
     * @return
     */
    @ApiOperation(value = "删除访客预约记录")
    @PostMapping(value = "/delAuditStatusById")
    public R<Boolean> delAuditStatusById (@RequestBody ReservationAuditRecordUpdateDTO reservationAuditRecordUpdateDTO) {

        return R.success(reservationAuditRecordService.delAuditStatusById(reservationAuditRecordUpdateDTO));
    }

}
